<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="author" content="林镭特">
    <title></title>
    <style>
        img{
            width: 50px;
            height: 50px;
            border-radius: 50%;
        }
    </style>
</head>
<body>
    <nav>
        <div class="logout">
            <img src="img/avatar.jpg" alt="">
           <a href="./edit.html"><span class="username"></span></a> 
            <a class="out" href="javascript:;">退出</a>
        </div>
        <div class="login">
            <a href="login.html">登录</a>
            <a href="register.html">注册</a>
        </div>
    </nav>
    <script src="https://cdn.bootcss.com/jquery/3.5.0/jquery.min.js"></script>
    <script src="./layer/layer.js"></script>
<script>
     $.get('/user',data=>{
        if (data.error == 0) {
            console.log(data);
            $('.login').hide();
            $('.logout').show().find('.username').text(data.user.username);
            $('.logout img').attr('src', data.user.avatar);
        } else {
            $('.login').show();
            $('.logout').hide().find('.username').text('');
        }
    });


    $('.out').click(()=>{
        $.get('/logout', data=>{
            layer.msg(data.txt);
            $('.login').show();
            $('.logout').hide().find('.username').text('');
        });
    });
</script>
</body>
</html>